package com.cysyz.mylib.dao.sqloperaterrevolver.impl;


import com.cysyz.mylib.dao.sqloperaterrevolver.SqlOperatorRevolver;

import java.util.List;

/**
 * Created by emall on 2014/7/30.
 */
public abstract class BaseSqlOperatorRevolver implements SqlOperatorRevolver {

    protected void addOneCond(StringBuilder sqlBuilder, List<Object> params, String column, String operator, Object value) {
        sqlBuilder.append(" and ");
        sqlBuilder.append(column);
        sqlBuilder.append(" ");
        sqlBuilder.append(operator);
        sqlBuilder.append(" ");
        sqlBuilder.append(this.getRight());

        params.add(value);
    }

    @Override
    public boolean support(StringBuilder sqlBuilder, List<Object> params, String column, String operator, Object value) {
        boolean support = false;
        List<String> supportOperatorList = getSupportOperatorList();
        for (String supportOperaotr : supportOperatorList) {
            if (supportOperaotr.equals(operator)) {
                support = true;
            }
        }
        return support;
    }

    protected abstract List<String> getSupportOperatorList();

    protected String getRight() {
        return "?";
    }
}
